home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1191
/
1191.xpi
/
chrome
/
reminderfox.jar
/
content
/
reminderfox
/
utils
/
rmFxUtils.js
< prev
Wrap
Text File
|
2009-11-05
|
11KB
|
291 lines
var gRmFx_Messenger; // TB1, TB2, TB3, PB, SM
var gRmFx_AB3; // true: TB/AB3 installed
/**
* Reminderfox Utilities - general
*/
function rmFxUtil () {
}
rmFxUtil.encodeUTF8 = function (text) {
// =========================================================================
return rmFxUtil.convertFromUnicode("UTF-8", text).replace(/(\r\n)|\n/g, "\r\n");
}
rmFxUtil.convertFromUnicode = function (aCharset, aSrc) {
// =========================================================================
var unicodeConverter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
unicodeConverter.charset = aCharset;
return unicodeConverter.ConvertFromUnicode(aSrc);
}
rmFxUtil.getIOService = function () {
// =========================================================================
if (rmFxUtil.getIOService.mObject === undefined) {
rmFxUtil.getIOService.mObject = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService2);
}
return rmFxUtil.getIOService.mObject;
}
rmFxUtil.buildUIDFile = function (rmFx_UID) {
// =========================================================================
var tempDir = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
tempDir.append( "tempMsg" + rmFx_UID );
return tempDir.path;
}
rmFxUtil.readInFileContents = function (tmpFile) {
// =========================================================================
var sfile = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
sfile.initWithPath(tmpFile);
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
rmFxUtil.PromptAlert("Permission to read file was denied. " + e.name + " -- " + e.message);
return null;
}
var is = Components.classes["@mozilla.org/network/file-input-stream;1"]
.createInstance( Components.interfaces.nsIFileInputStream );
try {
is.init( sfile,0x01, 00004, null);
}
catch ( e ) {
rmFxUtil.PromptAlert("Could not read reminder file: " + e.name + " -- " + e.message);
return null;
}
// Now, read from the stream
var scriptableStream = Components.classes["@mozilla.org/scriptableinputstream;1"]
.createInstance(Components.interfaces.nsIScriptableInputStream);
scriptableStream.init(is);
var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8"; // The character encoding you want, using UTF-8 here
var chunk = scriptableStream.read(scriptableStream.available());
scriptableStream.close();
var input = null;
try {
input = converter.ConvertToUnicode(chunk);
}
catch( e ) {
input = chunk;
}
return input;
}
rmFxUtil.makeMsgFile = function (content, tempFile) {
// =========================================================================
var sfile = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
try {
sfile.initWithPath(tempFile);
} catch (ex) {
return null;
}
if (sfile.exists()) {
sfile.remove(true);
}
sfile.create(sfile.NORMAL_FILE_TYPE, 0600);
var stream = Components.classes['@mozilla.org/network/file-output-stream;1']
.createInstance(Components.interfaces.nsIFileOutputStream);
stream.init(sfile, 2, 0x200, false); // open as "write only"
stream.write(content, content.length);
stream.close();
return sfile;
}
rmFxUtil.makeMsgFile8 = function (outputStr, file) {
// =========================================================================
var sfile = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
sfile.initWithPath(file);
var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance( Components.interfaces.nsIFileOutputStream );
outputStream.init( sfile, 0x04 | 0x08 | 0x20, 420, 0 );
var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8";
var chunk = null;
try {
chunk = converter.ConvertFromUnicode(outputStr);
}
catch( e ) {
chunk = outputStr;
}
outputStream.write(chunk, chunk.length);
var fin = converter.Finish();
if (fin.length > 0)
outputStream.write(fin, fin.length);
outputStream.close();
return sfile;
}
/**
* Debugging support, prompts an Alert and writes it to console
*/
rmFxUtil.PromptAlert = function (msgErr) {
// =========================================================================
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
promptService.alert(window, "ReminderFox Error", msgErr);
rmFxUtil.dump2Console (msgErr)
};
rmFxUtil.dump2Console = function (logString) {
// =========================================================================
// TB3/SM2/FX3: Application.console.log("reminderFox: " + logString)
var rmFx_consoleService = Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService);
rmFx_consoleService.logStringMessage("reminderFox: " + logString);
};
rmFxUtil.copytoClipboard = function (data) {
// =========================================================================
// Generic function to copy the data to Clipboard
var clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"];
clipboard = clipboard.getService(Components.interfaces.nsIClipboardHelper);
clipboard.copyString(data );
};
/**
*
* rmFxUtil Dialog Confirm Service to support 2 or 3 key choice
*
<br> [key0] [key1]
<br> or [key0] [key2] [key1]
*
* @param title, the headline of dialog
* @param msg, typically a question
* @param key0
* @param key1
* @param key2, optional, decides if 2 or 3 buttons
*/
rmFxUtil.ConfirmEx = function (title, msg, key0, key1, key2) {
// =========================================================================
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var flags =
promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0 +
promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_1; // flags = [integer] 32639
if (!!key2) {
var flags =
promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0 +
promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_1 +
promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_2; // flags = [integer] 8355711
}
return promptService.confirmEx(window,
title, msg, flags, key0, key1, key2, null, {});
};
// Utilities from \mail\components\preferences\applications.js
rmFxUtil.getDisplayNameForFile = function (aFile) { // +++2do gW_OSspecfic ???
// =========================================================================
/*
//@line 85 "e:\buildbot\win32_build\build\mail\components\preferences\applications.js"
*/
if (aFile instanceof Components.interfaces.nsILocalFileWin) {
try {
return aFile.getVersionInfoField("FileDescription");
}
catch(ex) {
// fall through to the file name
}
}
/*
//@line 108 "e:\buildbot\win32_build\build\mail\components\preferences\applications.js"
*/
return aFile.leafName;
}
rmFxUtil.getLocalHandlerApp = function (aFile) { // +++2do gW_OSspecfic ???
// =========================================================================
var localHandlerApp = Components.classes["@mozilla.org/uriloader/local-handler-app;1"]
.createInstance(Components.interfaces.nsILocalHandlerApp);
localHandlerApp.name = rmFxUtil.getDisplayNameForFile(aFile);
localHandlerApp.executable = aFile;
return localHandlerApp;
}
rmFxUtil.isValidHandlerExecutable = function (aExecutable) { // +++2do gW_OSspecfic ???
// =========================================================================
return aExecutable &&
aExecutable.exists() &&
aExecutable.isExecutable() &&
//@line 905 "e:\buildbot\win32_build\build\mail\components\preferences\applications.js"
aExecutable.leafName != ".exe";
//@line 913 "e:\buildbot\win32_build\build\mail\components\preferences\applications.js"
}
/* -----------
function about_startup() {
var label = document.getElementById('rmFx_Version').getAttribute("value");
var versionString = label + " " + REMINDER_FOX_MIGRATED_PREF_VERSION;
document.getElementById('rmFx_Version')
.setAttribute( "value", versionString );
var jarFile = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsIFile);
// FX and TB : ProfD\extensions\{ada4b710-8346-4b82-8199-5de2b400a6ae}\chrome\reminderfox.jar"
// SM: ProfD\chrome\reminderfox.jar"
var appId = Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULAppInfo);
// if ( appId.name != "SeaMonkey") {
jarFile.append( "extensions" );
jarFile.append( "{ada4b710-8346-4b82-8199-5de2b400a6ae}" );
// }
jarFile.append( "chrome" );
jarFile.append( "reminderfox.jar" );
var jar = new Date();
jar.setTime(jarFile.lastModifiedTime);
document.getElementById('logoText')
.setAttribute( "tooltiptext", "XPI as of: " + jar);
rmFxUtil.copytoClipboard("reminderfox.XPI as of: " + jar);
sizeToContent();
var version = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager)
.getItemForID("{ada4b710-8346-4b82-8199-5de2b400a6ae}").version
document.getElementById('rmFx_Version')
.setAttribute( "value", "v:" + version);
}
---------- */